package com.ruoyi.web.controller.lwpq;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lwpq.domain.LwpqPx;
import com.ruoyi.lwpq.service.ILwpqPxService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训Controller
 * 
 * @author ruoyi
 * @date 2022-03-16
 */
@Controller
@RequestMapping("/lwpq/px")
public class LwpqPxController extends BaseController
{
    private String prefix = "lwpq/px";

    @Autowired
    private ILwpqPxService lwpqPxService;

    @RequiresPermissions("lwpq:px:view")
    @GetMapping()
    public String px()
    {
        return prefix + "/px";
    }

    /**
     * 查询培训列表
     */
    @RequiresPermissions("lwpq:px:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LwpqPx lwpqPx)
    {
        startPage();
        lwpqPx.setCreateBy(getLoginName());
        List<LwpqPx> list = lwpqPxService.selectLwpqPxList(lwpqPx);
        return getDataTable(list);
    }

    /**
     * 导出培训列表
     */
    @RequiresPermissions("lwpq:px:export")
    @Log(title = "培训", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LwpqPx lwpqPx)
    {
        List<LwpqPx> list = lwpqPxService.selectLwpqPxList(lwpqPx);
        ExcelUtil<LwpqPx> util = new ExcelUtil<LwpqPx>(LwpqPx.class);
        return util.exportExcel(list, "培训数据");
    }

    /**
     * 新增培训
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存培训
     */
    @RequiresPermissions("lwpq:px:add")
    @Log(title = "培训", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LwpqPx lwpqPx)
    {
        lwpqPx.setCreateBy(getLoginName());
        return toAjax(lwpqPxService.insertLwpqPx(lwpqPx));
    }

    /**
     * 修改培训
     */
    @RequiresPermissions("lwpq:px:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LwpqPx lwpqPx = lwpqPxService.selectLwpqPxById(id);
        mmap.put("lwpqPx", lwpqPx);
        return prefix + "/edit";
    }

    /**
     * 修改保存培训
     */
    @RequiresPermissions("lwpq:px:edit")
    @Log(title = "培训", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LwpqPx lwpqPx)
    {
        lwpqPx.setUpdateBy(getLoginName());
        return toAjax(lwpqPxService.updateLwpqPx(lwpqPx));
    }

    /**
     * 删除培训
     */
    @RequiresPermissions("lwpq:px:remove")
    @Log(title = "培训", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lwpqPxService.deleteLwpqPxByIds(ids));
    }
}
